#include "portaudio.h"
#include "cassert"
#include <vector>
#include <stdio.h>
#include <exception>
#include "Waveform.h"


/* A class which will write audio to default outputs. */
class AudioPlayer { 
 
 private: 
  int  _sampleRate; 
  PaStream* _stream; 
  PaError _err;
  bool _hasSignal;   // says whether there is audio to play
  
  std::vector<float> _signal;
  int _lastIndex; // for remembering where we left off writing to the buffer
  
  int checkError(void);

 protected: 
  static int paOutputCallback( const void *inputBuffer, void *outputBuffer,
			       unsigned long framesPerBuffer,
			       const PaStreamCallbackTimeInfo* timeInfo,
			       PaStreamCallbackFlags statusFlags,
			       void *userData );
  
 public:   
  int startAudio(void);
  int stopAudio(void);  
  void setAudio(std::vector<float> signal, int sampleRate);
  void setAudio(Waveform& wfm);
  
}; 

